cc.Class({
    extends: cc.Component,

    properties: {
        title: cc.Sprite,
        tabBtns: [cc.Node],
        panels: [cc.Prefab],
        titleSpts: [cc.SpriteFrame],
    },

    onLoad () {
        for(var i in this.tabBtns) this.tabBtns[i].on('toggle', this.onToggle, this);
        this.currPanel = null;
        this.loadPanel(0);
    },

    onToggle(evt) {
        this.loadPanel(this.tabBtns.indexOf(evt.target));
    },

    loadPanel(index) {
        this.title.spriteFrame = this.titleSpts[index];
        if (index == 0){
            cc.Proxy.newburyingPoint(EventConfig.getEventId('赛况'));
        }else if (index == 1){
            cc.Proxy.newburyingPoint(EventConfig.getEventId('车况'));
        }else{
            cc.Proxy.newburyingPoint(EventConfig.getEventId('历史'));
        }
        if(this.currPanel) this.currPanel.parent = null;
        this.currPanel = cc.instantiate(this.panels[index]);
        this.currPanel.parent = this.node;
    }
});
